//最长回文子串
class Solution {
public:
    string longestPalindrome(string s) {
        int index = 0;
        int max_size = 0;
        int n = s.size();
        for (int i = 0; i < n; i++) {
            int left = i, right = i;
            while (left >= 0 && right <= n) {
                if (s[left] == s[right]) {
                    left--;
                    right++;
                } else {
                    break;
                }
            }
            if (max_size < (right - left - 1)) {
                max_size = right - left - 1;
                index = left + 1;
            }
            left = i;
            right = i + 1;
            while (left >= 0 && right <= n) {
                if (s[left] == s[right]) {
                    left--;
                    right++;
                } else {
                    break;
                }
            }
            if (max_size < (right - left - 1)) {
                max_size = right - left - 1;
                index = left + 1;
            }
        }
        return s.substr(index, max_size);
    }
};

//LCR 002. 二进制求和
class Solution {
public:
    string addBinary(string a, string b) {
        int n1 = a.size() - 1;
        int n2 = b.size() - 1;
        int t = 0;
        int sum;
        string ret;
        while (n1 >= 0 || n2 >= 0 || t) {
            sum = 0;
            if (n1 >= 0) {
                if (a[n1] == '1')
                    sum++;
                n1--;
            }
            if (n2 >= 0) {
                if (b[n2] == '1')
                    sum++;
                n2--;
            }
            if (t)
                sum++;
            if (sum >= 2)
                t = 1;
            else
                t = 0;
            ret += ('0' + (sum % 2));
        }
        reverse(ret.begin(), ret.end());
        return ret;
    }
};